package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AddNursingProjectDto;
import com.zzyl.dto.GetPageNursingsDto;
import com.zzyl.dto.UpdateNursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目")
public class NursingProjectController {
    @Autowired
    private NursingProjectService nursingProjectService;
    /**
     * 分页查询
     */
    @GetMapping()
    @ApiOperation(value = "分页查询")
    public ResponseResult<PageResponse<NursingProjectVo>> page(GetPageNursingsDto dto){

        PageResponse<NursingProjectVo> nursingProjectVoPageResponse= nursingProjectService.page(dto);

        return ResponseResult.success(nursingProjectVoPageResponse);
    }

    /**
     * 新增
     * @param dto
     * @return
     */
    @PostMapping()
    @ApiOperation(value = "新增护理项目")
    public ResponseResult insertNursingProject(@RequestBody AddNursingProjectDto dto){
        nursingProjectService.insertNursingProject(dto);
        return  ResponseResult.success();
    }

    /**
     * 修改回显
     * @param id
     * @return
     */
    @GetMapping("{id}")
    @ApiOperation(value = "修改回显")
    public ResponseResult getNursingProjectById(@PathVariable Integer id){
        NursingProject nursingProject= nursingProjectService.getNursingProjectById(id);
        return ResponseResult.success(nursingProject);
    }

    /**
     * 修改护理项目
     * @param dto
     * @return
     */
    @PutMapping()
    @ApiOperation(value = "修改护理项目")
    public ResponseResult updateNursingProjectById(@RequestBody UpdateNursingProjectDto dto){
        nursingProjectService.updateNursingProjectById(dto);
        return ResponseResult.success("修改成功");
    }

    /**
     * 删除护理项目
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    @ApiOperation(value = "删除护理项目")
    public ResponseResult deleteNursingProjectById(@PathVariable Integer id){
        nursingProjectService.deleteNursingProjectById(id);
        return ResponseResult.success("删除成功");
    }
    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult status(@PathVariable("id")Long id, @PathVariable("status")Integer status){
        nursingProjectService.status(id, status);
        return ResponseResult.success();
    }
//    nursing_project/all
    @ApiOperation(("查询全部"))
    @GetMapping("/all")
    public ResponseResult getAllNursingProject(){
      List<NursingProjectVo> nursingProjectVoList= nursingProjectService.getAllNursingProject();
      return ResponseResult.success(nursingProjectVoList);
    }

}
